package com.hx.base.servlet.velocity;

import java.text.NumberFormat;
import java.util.Date;

import com.hx.util.date.DateTool;
import com.hx.util.encode.EncodeUtil;

public class PageUtil {

    public static String getDate(Date date) {
        if (date == null) {
            return null;
        }
        return DateTool.getDate(date, "yyyy-MM-dd");
    }

    public static String getDateTime(Date date) {
        if (date == null) {
            return null;
        }
        return DateTool.getDate(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String getDateTime2(Date date) {
        if (date == null) {
            return null;
        }
        return DateTool.getDate(date, "yyyy/MM/dd HH:mm");
    }

    public static String getTime(Date date) {
        if (date == null) {
            return null;
        }
        return DateTool.getDate(date, "HH:mm:ss");
    }

    /**
     * 保留几位小数，显示的最后位是舍入的
     * @param number
     * @param fractionDigits 显示的小数的位数
     * @return 
     */
    public static String getNumber(Double number, int fractionDigits) {
        if (number == null) {
            return null;
        }
        NumberFormat format = NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(fractionDigits);
        return format.format(number);
    }
   /* public static Arith getArith(){
        return new Arith();
    }
    public static String getFormatedMoney(Double money) {
        return CurrencyTool.getCHS(money);
    }*/
   /*
    * 页面转码
    */
    public static String encode(String str,String encode){
    	return EncodeUtil.encode(str, encode);
    }
    
    /*
     * UTF-8页面转码
     */
    public static String encode(String str){
    	return EncodeUtil.encode(str);
    }
    
    public static void main(String[] args) {
        System.out.println(PageUtil.getDate(new Date()));
        System.out.println(PageUtil.getDateTime(new Date()));
        System.out.println(encode("李医生","UTF-8"));
        //encodeURIComponent(str)
    }
}
